package tau.dimes.tasks;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

import tau.dimes.data.Table;
import tau.dimes.data.TableException;
import tau.dimes.db.DatabaseException;
import tau.dimes.ipGeo.IpGeoException;
import tau.dimes.ipGeo.IpGeoFactory;
import tau.dimes.ipGeo.IpGeoProviderImpl;

public class TranslateIpGeoTask extends FutureTask<Object>
{
	public static final String LATITUDE_COLUMN = "latitude";
	public static final String LONGITUDE_COLUMN = "longitude";

	public TranslateIpGeoTask(final Table table, final int ipColumn)
	{
		super(new Callable<Object>() {
			@Override
			public Object call() throws Exception
			{
				translateIpGeo(table, ipColumn);
				return null;
			}
		});
	}

	private static void translateIpGeo(Table table, int ipColumn) throws IpGeoException,
		DatabaseException, TableException
	{
		IpGeoProviderImpl provider = IpGeoFactory.create();
		provider.translate(table, ipColumn, LATITUDE_COLUMN, LONGITUDE_COLUMN);
	}
}
